<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>GO 博客 - 分类</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin" style="padding: 15px;">
        <form class="layui-form" style="display: inline;">
            <input type="text" name="keywords" required  lay-verify="required" placeholder="请输入部位名称" class="layui-input radius" autocomplete="off" style="max-width: 400px;display: inline;margin: -10px 10px 0 0;" />
            <button class="layui-btn layui-btn-danger" style="margin-top: -2px;" lay-submit="" lay-filter="vaeform"><i class="layui-icon">&#xe615;</i> 搜索</button>
        </form>
        {{ .List }}
        <table class="layui-hide" id="test" lay-filter="test"></table>
    </div>
</body>

<script src="/static/layui/layui.js"></script>
<script>
    layui.use(['table', 'form', 'layer'], function(){
        var table = layui.table
            ,layer = layui.layer
            ,$ = layui.$
            ,form = layui.form;

        var tableIns = table.render({
            elem: '#test'
            ,toolbar: '#toolbarDemo'
            ,url: '/' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'id', title: 'ID', sort: true, align:'center', width: 150}
                ,{field: 'position', title: '分类名称', align:'center'}
                ,{title: '操作', align:'center', toolbar: '#action'}
            ]]
        });

        //监听搜索提交
        form.on('submit(vaeform)', function(data){
            if(data.field.keywords) {
                tableIns.reload({where:{keywords:data.field.keywords}});
                vae.bundledTab();
            }
            return false;
        });

        // 删除
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del') {
                layer.confirm('真的删除行么', {icon: 3, title: '提示'}, function (index) {
                    $.ajax({
                        url: "{:url('Position/delPositionSubmit')}",
                        data: {id: data.id},
                        success: function (res) {
                            layer.msg(res.msg);
                            if (res.code == 1) {
                                obj.del();
                            }
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });


    function addPosition(){
        layer.open({
            type: 2,
            title: false,
            closeBtn: 0, //不显示关闭按钮
            shade: [0.3],
            shadeClose: true,
            area: ['40%', '30%'],
            anim: 1,
            content: ['{:url("Position/editPosition")}', 'no'], //iframe的url，no代表不显示滚动条
        });
    }

    function editPosition(id){
        layer.open({
            type: 2,
            title: false,
            closeBtn: 0, //不显示关闭按钮
            shade: [0.3],
            shadeClose: true,
            area: ['40%', '30%'],
            anim: 1,
            content: ['/detection/Position/editPosition/id/' + id, 'no'], //iframe的url，no代表不显示滚动条
        });
    }
</script>

</html>